package com.atguigu.guli.edu.controller.admin;


import com.atguigu.guli.edu.entity.Chapter;
import com.atguigu.guli.edu.service.EduChapterService;
import com.atguigu.guli.service.base.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


@RestController
@RefreshScope
@Api(tags = "章节信息")
@RequestMapping("/admin/edu/chapter")
public class AdminEduChapterController {

    @Value("${myName}")
    String name;

    @GetMapping
    public String test(){
        return name;
    }
    @Autowired
    private EduChapterService eduChapterService;

    @ApiOperation("添加章节")
    @PostMapping("/save")
    public R saveChapter(@RequestBody Chapter chapter){
        eduChapterService.save(chapter);
        return R.ok();
    }

    @ApiOperation("修改章节")
    @PutMapping("/update")
    public R updateChapter(@RequestBody Chapter chapter){
        eduChapterService.updateById(chapter);
        return R.ok();
    }

    @ApiOperation("查询章节信息")
    @GetMapping("/list/{id}")
    public R listPage(@PathVariable("id") String courseId){
        List<Chapter> chapters = eduChapterService.queryPage(courseId);
        return R.ok().data("data",chapters);
    }

    @ApiOperation("查询章信息")
    @GetMapping("/select/{id}")
    public R selectId(@PathVariable("id")String id){
        Chapter chapter = eduChapterService.getById(id);
        return R.ok().data("data",chapter);
    }

}